from abc import ABC, abstractmethod
from typing import Dict, Any, Optional
from pathlib import Path
from ..logger import test_logger

class BaseReportSender(ABC):
    """报告发送器基类"""
    
    def __init__(self, config: Dict[str, Any]):
        """初始化发送器
        
        Args:
            config: 配置信息
        """
        self.config = config
        self.logger = test_logger.get_logger(self.__class__.__name__)
        
    @abstractmethod
    def send_report(self, report_path: Path, title: str, content: Optional[str] = None) -> bool:
        """发送测试报告
        
        Args:
            report_path: 报告文件路径
            title: 报告标题
            content: 报告内容（可选）
            
        Returns:
            是否发送成功
        """
        pass
        
    def _validate_config(self, required_keys: list) -> bool:
        """验证配置信息
        
        Args:
            required_keys: 必需的配置键列表
            
        Returns:
            配置是否有效
        """
        for key in required_keys:
            if key not in self.config:
                self.logger.error(f"Missing required config key: {key}")
                return False
        return True 